﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Data;
using BookingSystemBLL;
using BookingSystemDAL;
using BookingSystemModel;


public partial class BookingTicket : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
       /*
        if (!IsPostBack)
        {
            BindData();
        }
        */
    }
    protected void GridView_lookup_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView_lookup.PageIndex = e.NewPageIndex;
        BindData();
    }

    public void BindData()
    {
        GridView_lookup.AllowPaging = true;//是否启用分页
        GridView_lookup.PageSize = 10;//每页显示条数
        DataSet dataset = FlightBLL.GetAllFlight();
        this.GridView_lookup.DataSource = dataset.Tables[0];
        this.GridView_lookup.DataBind();//绑定数据源

#region 
        /*
        if (GridView_lookup.PageIndex == 0)
        {
            this.LinkButton1.Enabled = false;
            this.LinkButton2.Enabled = false;
        }
        else
        {
            this.LinkButton1.Enabled = true;
            this.LinkButton2.Enabled = true;
        }

        if (GridView_lookup.PageIndex == GridView_lookup.PageCount - 1)
        {
            this.LinkButton3.Enabled = false;
            this.LinkButton4.Enabled = false;
        }
        else
        {
            this.LinkButton3.Enabled = true;
            this.LinkButton4.Enabled = true;
        }
       */
#endregion
        
    }
    protected void SearchTicket_Click(object sender, EventArgs e)
    {
       
         string FromAddress =this.From_station.Text;
        string ToAddress = this.To_station.Text;
        string  FromDate =this.From_time.Text;
        DataSet ds = FlightBLL.GetDCFlight(FromAddress, ToAddress, FromDate);
        GridView_lookup.DataSource = ds.Tables[0];
        GridView_lookup.DataBind();   
    }
    protected void GridView_lookup_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {

    }
    protected void GridView_lookup_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
       string FlightNumber =( ((LinkButton)sender).CommandArgument.ToString()).ToString();
        Session["FlightNumber"] = FlightNumber;
        DataSet dataset = FlightBLL.GetFlightByFlightNumber(FlightNumber);
        string mahua = dataset.Tables[0].Rows[0][0].ToString();
        string mahua1 = dataset.Tables[0].Rows[0]["FlightType"].ToString();
        if (Convert.ToInt32(dataset.Tables[0].Rows[0][3] )> 0 || Convert.ToInt32(dataset.Tables[0].Rows[0][5]) > 0 || Convert.ToInt32(dataset.Tables[0].Rows[0][7] )> 0)
            Response.Redirect("PreBookingTicket.aspx");//将FlightNumber这个主键传递到PreBookingticket.asp页面，再在该页面根据该主键查询航班
        else
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此航班已售完!');</script>");
    }

    protected void GridView_lookup_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "LinkButtonBooking")
        {
            GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);//获取被点击的linkButton所在的GridViewRow
            int index = gvrow.RowIndex;//获取到行索引
            string FlightNumber = this.GridView_lookup.Rows[index].Cells[1].Text.Trim();
            Session["mahua"] = FlightNumber;
        } 
        else
        {
        }
    }
}